package com.jing.cloud.service.user.method;

import com.google.common.collect.Maps;
import com.jing.cloud.service.method.AbstractMethod;
import com.jing.cloud.service.method.Method;
import com.jing.cloud.service.user.bean.User;
import com.jing.cloud.service.user.dao.UserDao;
import com.jing.cloud.service.user.method.param.FindUserBean;
import com.jing.cloud.service.util.db.Compare;
import com.jing.cloud.service.util.db.Page;
import com.jing.cloud.service.Res;
import com.jing.cloud.util.RspUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created by 29017 on 2017/9/21.
 */
@Component
public class FindUser extends AbstractMethod<FindUserBean> implements Method<FindUserBean> {

    @Autowired
    private UserDao userDao;

    @Override
    public Res call(FindUserBean findUserBean) throws Exception {
        Map<String, Object> condition = Maps.newHashMap();
        Compare cNickname = new Compare();
        cNickname.setLike("%" + findUserBean.getNickname() + "%");
        condition.put("nickname", cNickname);
        Page<User> page = new Page<>();
        page.setPage(1);
        page.setPage(findUserBean.getSize());
        page = userDao.query(condition, page);
        return RspUtil.success(page.getList());
    }
}
